package com.presto.directo.mvvm.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.presto.directo.R
import com.presto.directo.base.XApplication
import com.presto.directo.entity.LoanStatusEntity
import com.presto.directo.utils.appendAmountUnit
import com.presto.directo.utils.appendDayUnit

class RecordListAdapter(layoutResId: Int) : BaseQuickAdapter<LoanStatusEntity, BaseViewHolder>(layoutResId) {
    override fun convert(holder: BaseViewHolder, item: LoanStatusEntity) {
        with(item) {
            holder.setText(R.id.tv_status, status[loan_status] ?: "")
            holder.setText(R.id.tv_order, XApplication.application.getString(R.string.text_order_title) + busiId)
            holder.setText(R.id.tv_apply_time, XApplication.application.getString(R.string.text_loan_time) + ": " + item.app_time)
            holder.setText(R.id.tv_apply_amount, item.principal.appendAmountUnit())
            holder.setText(R.id.tv_duration, item.duration.appendDayUnit())
            holder.setGone(R.id.btn_repay, item.loan_status != "5" && item.loan_status != "7")
            holder.setText(R.id.tv_repay_amount, item.paymentAmount.appendAmountUnit())
            holder.setGone(R.id.rl_repay_time, item.deadline.isEmpty())
            holder.setText(R.id.tv_repay_time, item.deadline)
            holder.setText(R.id.tv_interest_amount, item.interest.appendAmountUnit())
            holder.setText(R.id.tv_penalty_amount, item.penalty.appendAmountUnit())
            holder.setGone(R.id.tv_more, item.loan_status.isEmpty() || item.loan_status == "2" || item.loan_status == "3")
            holder.setGone(R.id.rl_manage, item.manager_fee.isBlank())
            holder.setText(R.id.tv_manage_amount, item.manager_fee.appendAmountUnit())
        }

    }

    override fun convert(holder: BaseViewHolder, item: LoanStatusEntity, payloads: List<Any>) {
        super.convert(holder, item, payloads)
        holder.setGone(R.id.ll_detail, !item.expand)
    }

    private val status by lazy {
        mapOf(
            "1" to "Solicitud en trámite",
            "2" to "Cancelar préstamo",
            "3" to "Solicitud fallada",
            "4" to "Solicitud exitosa",
            "5" to "Pago en proceso",
            "6" to "Pagado",
            "7" to "Vencido",
            "8" to "Liquidado",
            "9" to "Préstamo fallado"
        )
    }
}